package cn.ex;

import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class Ex1 {
    public static void main(String[] args) {
        String str = "hello1java456mysql7html124322css";
        System.out.println(str);

        //[0-9]{1,}
        System.out.println(str.replaceAll("\\d+", "-")); //贪婪模式
        System.out.println(str.replaceAll("\\d+?", "-")); //禁用贪婪模式，使用 ?
        System.out.println(str.replaceAll("\\d", "-")); //禁用贪婪模式，使用 ?


        String h = """
                <div>myjavaok</div><p>java<div>java18</div></p><span>javascript</span><div>hellojava</div>
                """;
        System.out.println(h);
        System.out.println("------------------------");
        Pattern pattern = Pattern.compile("<div>.*?java.*?</div>"); //禁用贪婪
        Matcher m = pattern.matcher(h);
        while(m.find()){
            System.out.println(m.group());
        }

        //正则表达式分组 把<div></div> 标签中的java改为abc
        System.out.println(h);
        System.out.println(h.replace("java","abc"));
        System.out.println(h.replaceAll("(<div>.*?)(java)(.*?</div>)","$1abc$3"));


    }

}
